﻿using BuyWithoutLoseMoney;
using BuyWithoutLoseMoney.Core.Models;
using BuyWithoutLoseMoney.Core.Repositories;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Org.BouncyCastle.Math.EC.Rfc7748;
using System.Linq;
using System.Threading.Tasks;

namespace BuyWithoutLose.Areas.Admin.Controllers
{
    /// <summary>
    /// 订单详情
    /// </summary>    
    [Area("admin")]
    public class OrderdetailsController : BaseAdminController
    {

        private readonly IRepository<OrderDetails, int> _orderDetailsRepository;
        private readonly IRepository<Order, int> _orderRepository;
        private readonly IRepository<Product, int> _productRepository;
        private readonly IRepository<User,int> _userRepository;
        private readonly IRepository<UserAddress, int> _userAddressRepository;

        public OrderdetailsController(IRepository<Order, int> orderRepository,IRepository<OrderDetails, int> orderDetailsRepository, 
            IRepository<Product, int> productRepository,IRepository<User,int> userRepository,
            IRepository<UserAddress, int> userAddressReposito
            , BuyWithoutLoseMoneyDBContext db) : base(db)
        {
            _userRepository = userRepository;
            _orderDetailsRepository = orderDetailsRepository;
            _orderRepository = orderRepository;
            _productRepository = productRepository;
            _userAddressRepository = userAddressReposito;
        }

        /// <summary>
        /// 订单详情
        /// </summary>
        public async Task<IActionResult> Index(int id = 0)
        {
            var orderDe = _orderDetailsRepository.GetAll();
            var OrderDe = orderDe.Include("Product").Where(x => true);
            if (id != 0)
            {
                OrderDe = OrderDe.Where(x => x.OrderId == id);
            }
            ViewBag.OrderDe = orderDe;
            var User=await _userRepository.GetAllListAsync();
            ViewBag.User = User;
            var product=await _productRepository.GetAllListAsync();
            ViewBag.Product = product;
            var order=await _orderRepository.GetAllListAsync();
            ViewBag.Order = order;
            var userAddress = await _userAddressRepository.GetAllListAsync();
            ViewBag.UserAddress = userAddress;
            ViewBag.Id = id;
            return View(OrderDe);
        }
       
    }
}
 